home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / Asm / AB3DIIsrc / source_4000 / SERIAL_NIGHTMARE < prev    next >
Encoding:
Text File  |  1996-07-29  |  3.9 KB  |  293 lines

  1. ;sends the lower byte of d1 accross serial port
  2. ;corrupts bit 8 of d1
  3. SERSEND:
  4.     btst.b    #5,SERDATR(a6)
  5.     beq.s    SERSEND        ;wait until last byte sent
  6.     and.w    #$00FF,d1
  7.     bset.l    #8,d1        ;add stop bit
  8.     move.w    d1,SERDAT(a6)
  9.     rts
  10.     
  11. ;waits for serial data and returns it in 
  12. ;lower byte of d1
  13. SERREC:
  14.     btst.b    #6,SERDATR(a6)
  15.     beq.s    SERREC
  16.     move.w    SERDATR(a6),d1
  17.     move.w    #$0800,INTREQ(a6)
  18.     and.w    #$00ff,d1
  19.     rts
  20.  
  21. ;sends and receives an interleaved long word
  22. ;from d0 into d0 (sends first)
  23. SENDFIRST:
  24.     move.b    d0,d1
  25.     bsr.s    SERSEND
  26.     bsr.s    SERREC
  27.     move.b    d1,d2
  28.     ror.l    #8,d2
  29.     lsr.w    #8,d0
  30.     move.b    d0,d1
  31.     bsr.s    SERSEND
  32.     bsr.s    SERREC
  33.     move.b    d1,d2
  34.     ror.l    #8,d2
  35.     swap    d0
  36.     move.b    d0,d1
  37.     bsr.s    SERSEND
  38.     bsr.s    SERREC
  39.     move.b    d1,d2
  40.     ror.l    #8,d2
  41.     lsr.w    #8,d0
  42.     move.b    d0,d1
  43.     bsr.s    SERSEND
  44.     bsr.s    SERREC
  45.     move.b    d1,d2
  46.     ror.l    #8,d2
  47.     move.l    d2,d0
  48.     rts
  49.     
  50. ;sends and receives an interleaved long word
  51. ;from d0 into d0 (receives first)
  52. RECFIRST:
  53.     bsr.s    SERREC
  54.     move.b    d1,d2
  55.     move.b    d0,d1
  56.     bsr.s    SERSEND
  57.     ror.l    #8,d2
  58.     bsr.s    SERREC
  59.     move.b    d1,d2
  60.     lsr.w    #8,d0
  61.     move.b    d0,d1
  62.     bsr.s    SERSEND
  63.     ror.l    #8,d2
  64.     bsr.s    SERREC
  65.     move.b    d1,d2
  66.     swap    d0
  67.     move.b    d0,d1
  68.     bsr.s    SERSEND
  69.     ror.l    #8,d2
  70.     bsr.s    SERREC
  71.     move.b    d1,d2
  72.     lsr.w    #8,d0
  73.     move.b    d0,d1
  74.     bsr    SERSEND
  75.     ror.l    #8,d2
  76.     move.l    d2,d0
  77.     rts
  78.  
  79. PAUSE MACRO
  80.  move.l #0,tstchip
  81.  move.l #0,tstchip
  82.  move.l #0,tstchip
  83.  move.l #0,tstchip
  84.  move.l #0,tstchip
  85.  move.l #0,tstchip
  86.  move.l #0,tstchip
  87.  ENDM
  88.  
  89. INITSEND:
  90.  move.l #$bfd000,a0
  91.  move.w #15,d7
  92.  move.l #$bfe001,a3
  93.  rts
  94.  
  95. SENDLONG:
  96.  bset #6,(a0)
  97.  PAUSE
  98.  WT
  99.  move.w d7,d6
  100. SENDLOOP:
  101.  add.l d0,d0
  102.  bcc.s SENDZERO
  103.  bset #7,(a0)
  104.  bra.s SEND1
  105. SENDZERO:
  106.  bclr #7,(a0)
  107. SEND1:
  108.  PAUSE
  109.  bclr #6,(a0)
  110.  PAUSE
  111.  WTNOT
  112.  add.l d0,d0
  113.  bcc.s SENDZERO2
  114.  bset #7,(a0)
  115.  bra.s SEND12
  116. SENDZERO2:
  117.  bclr #7,(a0)
  118. SEND12:
  119.  PAUSE
  120.  bset #6,(a0)
  121.  PAUSE
  122.  WT
  123.  dbra d6,SENDLOOP
  124.  
  125.  bclr #7,(a0)
  126.  bclr #6,(a0)
  127. balls:
  128.  btst #3,(a0)
  129.  beq.s balls
  130.  rts
  131.  
  132. SENDLAST:
  133.  bset #6,(a0)
  134.  PAUSE
  135.  WT
  136.  move.w d7,d6
  137. SENDLOOPLAST:
  138.  add.l d0,d0
  139.  bcc.s SENDZEROLAST
  140.  bset #7,(a0)
  141.  bra.s SEND1LAST
  142. SENDZEROLAST:
  143.  bclr #7,(a0)
  144. SEND1LAST:
  145.  PAUSE
  146.  bclr #6,(a0)
  147.  PAUSE
  148.  WTNOT
  149.  
  150.  add.l d0,d0
  151.  bcc.s SENDZERO2LAST
  152.  bset #7,(a0)
  153.  bra.s SEND12LAST
  154. SENDZERO2LAST:
  155.  bclr #7,(a0)
  156. SEND12LAST:
  157.  PAUSE
  158.  bset #6,(a0)
  159.  PAUSE
  160.  WT
  161.  dbra d6,SENDLOOPLAST
  162.  
  163.  bset #7,(a0)
  164.  PAUSE
  165.  bclr #6,(a0)
  166.  PAUSE
  167. ballsLAST:
  168.  btst #3,(a0)
  169.  beq.s ballsLAST
  170.  rts
  171.  
  172.  
  173. INITREC:
  174.  move.l #$bfd000,a0
  175.  move.l #BUFFER,a1
  176.  move.w #15,d7
  177.  move.l #$bfe001,a3
  178.  rts
  179.  
  180. BACKRECEIVE
  181.  PAUSE
  182.  bclr #6,(a0)
  183.  PAUSE
  184.  bset #7,(a0)
  185.  move.l d0,(a1)+
  186.  
  187. RECEIVE:
  188.  PAUSE
  189.  WT
  190.  bclr.b #7,(a0)
  191.  move.w d7,d6
  192. RECIEVELOOP:
  193.  bset #6,(a0)
  194.  PAUSE
  195.  WTNOT
  196.  add.l d0,d0
  197.  btst #3,(a0)
  198.  beq.s noadd1
  199.  addq #1,d0
  200. noadd1:
  201.  PAUSE
  202.  bclr #6,(a0)
  203.  PAUSE
  204.  WT
  205.  PAUSE
  206.  add.l d0,d0
  207.  btst #3,(a0)
  208.  beq.s noadd2
  209.  addq #1,d0
  210. noadd2:
  211.  dbra d6,RECIEVELOOP
  212.  PAUSE
  213.  bset #6,(a0)
  214.  PAUSE
  215.  WTNOT
  216.  PAUSE
  217.  btst #3,(a0)
  218.  beq BACKRECEIVE
  219.  PAUSE
  220.  bset #7,(a0)
  221.  bclr #6,(a0)
  222.  move.l d0,(a1)+
  223.  rts
  224.  
  225. BUFFER: ds.l 2000
  226.  
  227. ;Before calling either of the transmission routines, the
  228. ;appropriate initialisation routine must be called
  229. ;(only once).
  230. ;The master _MUST_ use the ParSendFirst routine, and the
  231. ;slave _MUST_ use the ParRecFirst routine.
  232.  
  233. InitParSlave:
  234.     move.b    #%00000001,$bfd200
  235.     rts
  236.     
  237. InitParMaster:
  238.     move.b    #%00000010,$bfd200
  239.     rts
  240.  
  241. SENDPAR:    
  242. ParSendFirst:
  243.     move.w    #3,d2
  244. slp1:    btst    #1,$bfd000
  245.     beq.s    slp1
  246.     move.b    #$ff,$bfe301
  247.     move.b    d0,$bfe101
  248.     bset    #0,$bfd000
  249. slp2:    btst    #1,$bfd000
  250.     bne.s    slp2
  251.     move.b    #0,$bfe301
  252.     bclr    #0,$bfd000
  253. slp3:    btst    #1,$bfd000
  254.     beq.s    slp3
  255.     move.b    $bfe101,d1
  256.     bset    #0,$bfd000
  257. slp4:    btst    #1,$bfd000
  258.     bne.s    slp4
  259.     bclr    #0,$bfd000
  260.     lsr.l    #8,d0
  261.     ror.l    #8,d1
  262.     dbra    d2,slp1
  263.     move.l d1,d0
  264.     rts
  265.  
  266. RECPAR:    
  267. ParRecFirst:
  268.     move.w    #3,d2
  269. rlp1:    move.b    #0,$bfe301
  270.     bset    #1,$bfd000
  271. rlp2:    btst    #0,$bfd000
  272.     beq.s    rlp2
  273.     move.b    $bfe101,d1
  274.     bclr    #1,$bfd000
  275. rlp3:    btst    #0,$bfd000
  276.     bne.s    rlp3
  277.     move.b    #$ff,$bfe301
  278.     move.b    d0,$bfe101
  279.     bset    #1,$bfd000
  280. rlp4:    btst    #0,$bfd000
  281.     beq.s    rlp4
  282.     move.b    #0,$bfe301
  283.     bclr    #1,$bfd000
  284. rlp5:    btst    #0,$bfd000
  285.     bne.s    rlp5
  286.     
  287.     lsr.l #8,d0
  288.     ror.l #8,d1
  289.     
  290.     dbra    d2,rlp1
  291.     move.l d1,d0
  292.     rts
  293.